package com.gaofeng.day22.a11ThreadDemo;

public class Foodie extends Thread {
    @Override
    public void run() {
        /**
         * 循环
         * 同步代码块
         */
        while (true) {
            synchronized (Desk.lock) {
                if (Desk.count == 0) {
                    break;
                } else {
                    if (Desk.foodFlag == 0) {
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    } else {
                        Desk.count--;
                        System.out.println("吃货吃了一碗，还剩" + Desk.count + "没吃完");
                        Desk.lock.notifyAll();
                        // 修改状态
                        Desk.foodFlag = 0;
                    }
                }
            }
        }
    }
}
